package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 04
 * Time:11:45
 */

/***
 * 反转一个链表
 * prev——指向当前需要反转的节点的前驱
 * newHead——指向链表的头结点
 * curNext——指向需要反转的以一个节点
 */
public class Test4 {
    public ListNode reverseList(ListNode listNode){

        ListNode head = listNode;
        ListNode cur = head;
        ListNode newHead = null;
        ListNode prev = null;
        while(cur != null){
            ListNode curNext = cur.next;
            if(curNext == null){
                newHead = cur;
            }
            cur.next = curNext;
            prev = cur;
            cur = curNext;
        }
        return newHead;
    }
}
